home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************************
- ********************************************************************************
- ********************************************************************************
-
- PERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
- THIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
-
- P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
-
-
- ********************************************************************************
- ********************************************************************************
- *******************************************************************************/
-
- #include "header.h"
- #include "planets.h"
-
- /*rand number between 0 and X*/
- rnd(s,x)
- int s,x;
- {
- int i;
-
- do
- {
- i=(int)(abs(rand()%100));
- }
- while ((i<s)||(i>x));
- return(i);
- }
-
- add(xx,y,cc)
- int xx,y;
- char cc;
- {
- char *malloc();
- struct thing *a,*p,*r;
-
- if (univ[y]==NULL)
- {
- univ[y]=(struct thing *)malloc(sizeof(struct thing));
- univ[y]->x=xx;
- univ[y]->c=cc;
- univ[y]->next_thing=NULL;
- } else
- {
- r=(struct thing *)malloc(sizeof(struct thing));
- r->x=xx;
- r->c=cc;
-
- a=univ[y]; p=a->next_thing;
- while ((p!=NULL)&&(p->x<=xx))
- {
- a=p;
- p=p->next_thing;
- }
- if ((a==univ[y])&&(a->x>xx))
- {
- univ[y]=r;
- r->next_thing=a;
- } else
- {
- a->next_thing=r;
- r->next_thing=p;
- }
- }
- }
-
- setupuniverse()
- {
-
- newgame();
-
- for (i=0; i<10; ++i)
- players[i]=0;
-
- for (i=0; i<918; ++i)
- {
- univ[i]=NULL;
- }
-
- add(225,225,'*');
- add(225,675,'*');
- add(675,225,'*');
- add(675,675,'*');
-
- add(680,680,'k');
- add(670,670,'k');
- add(564,662,'k');
- add(470,488,'k');
-
- add(498,199,'#');
- add(501,197,'#');
- add(504,199,'#');
- add(498,203,'#');
- add(501,205,'#');
- add(504,203,'#');
-
- add(501,201,'o');
-
-
- /*planets*/
-
- for (r=0; r<30; ++r)
- {
- /*draw a planet....*/
- add(plan[r].xpos,plan[r].ypos,'O');
- }
-
- /*set up stars*/
- for (x=100; x<770; x+=60)
- {
- for (y=100; y<770; y+=25)
- {
- do
- {
- i=rnd(0,10);
- j=rnd(0,15);
- }
- while (!(inuniv(x+i,y+j)==NULL));
- k=rnd(0,100);
- if (k<50)
- add(x+i,y+j,'.'); else
- add(x+i,y+j,'@');
- }
- }
- }
-
- inuniv(xx,y)
- int xx,y;
- {
- register struct thing *p;
-
- p=univ[y];
-
- while (p!=NULL)
- {
- if (p->x==xx) return(p->c);
- p=p->next_thing;
- }
-
- return(NULL);
- }
-
-